<template>
  <div ref="wrapper">
    <slot></slot>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  props: {
  	probeType: {
  		type: Number,
  		default: true
  	},
  	click: {
  		type: Boolean,
  		default: true
  	},
  	data: {
  		type: Array,
  		default: null 
  	},
    //这个变量的意思是要不要监听滚动的信息默认值给的false
    listenScroll: {
      type: Boolean,
      default: false
    }
  },
 mounted() {
      setTimeout(() => {
        this._initScroll()
      }, 20)
    },
    methods: {
      _initScroll() {
        if (!this.$refs.wrapper) {
          return
        }
        this.scroll = new BScroll(this.$refs.wrapper, {
          probeType: this.probeType,
          click: this.click
        })
        //如果存在滚动值为true写一个滚动事件pos为位置向listview触发一个scroll滚动事件将参数传过去
        if (this.listenScroll) {
          let me = this
          this.scroll.on('scroll', (pos) => {
            me.$emit('scroll', pos)
          })
        }
  	},
  	// 当this.scroll灿在的时候调用scrll的这三个方法
  	disable() {
        this.scroll && this.scroll.disable()
      },
      enable() {
        this.scroll && this.scroll.enable()
      },
      refresh() {
        this.scroll && this.scroll.refresh()
      },
      //这两个是better-scroll的滚动到那个位置的方法
       scrollTo() {
        this.scroll && this.scroll.scrollTo.apply(this.scroll, arguments)
      },
      scrollToElement() {
        this.scroll && this.scroll.scrollToElement.apply(this.scroll, arguments)
      }
    },
  watch: {
  	data () {
  		setTimeout(() => {
        this.refresh()
  		},20)
  	}
  }
}
</script>

<style lang="stylus" scoped>
	
</style>